public class CPU {
    private int speed; // CPU 的速度

    public CPU(int speed) {
        setSpeed(speed);
    }

    public int getSpeed() {
        return speed;
    }

    public void setSpeed(int m) {
        if (m > 0) {
            this.speed = m;
        } else {
            throw new IllegalArgumentException("Speed must be positive.");
        }
    }

    @Override
    public String toString() {
        return String.format("Speed: %d MHz", speed);
    }
}

